import {isUrl} from '../utils/utils';

const menuData = [
  {
    name: '首页',
    icon: 'dashboard',
    path: 'dashboard',
    children: [
      {
        name: '概况',
        path: 'analysis',
      },
      /*{
       name: '监控页',
       path: 'monitor',
       },
       {
       name: '工作台',
       path: 'workplace',
       // hideInBreadcrumb: true,
       // hideInMenu: true,
       },*/
    ],
  },
  {
    name: '商品管理',
    icon: 'shop',
    path: 'goods',
    children: [
      {
        name: '商品列表',
        path: 'goods-list',
      },
      {
        name: '商品新增',
        path: 'goods-add',
      },
    ],
  },
  {
    name: '订单管理',
    icon: 'red-envelope',
    path: 'order',
    children: [
      {
        name: '订单概况',
        path: 'analysis',
      },
      {
        name: '订单列表',
        path: 'order-list',
      },
      {
        name: '结算管理',
        path: 'business-pay',
        authority: 'admin',
      },
      {
        name: '待结算详情',
        path: 'business-unpay',
        hideInMenu: true,
        authority: 'admin',
      },
      {
        name: '已结算详情',
        path: 'business-pay-detail',
        hideInMenu: true,
        authority: 'admin',
      },
      {
        name: '订单详情',
        path: 'order-detail',
        hideInMenu: true,
      },
      /*{
       name: '评价管理',
       path: 'comment-list',
       },*/
      {
        name: '退款维权',
        path: 'refund-list',
      },
      {
        name: '维权详情',
        path: 'refund-detail',
        hideInMenu: true,
      },
    ],
  },
  {
    name: '用户管理',
    icon: 'team',
    path: 'user',
    children: [
      {
        name: '用户列表',
        path: 'user-list',
      },
      {
        name: '商家列表',
        path: 'business-list',
        authority: 'admin',
      },
      {
        name: '概览分析',
        path: 'analysis',
      },
    ],
  },
  {
    name: '促销管理',
    icon: 'pay-circle-o',
    path: 'sales',
    authority: 'admin',
    children: [
      {
        name: '限时促销',
        path: 'discount-list',
      },
      {
        name: '限时促销新增',
        path: 'discount-add',
        hideInMenu: true,
      },
      {
        name: '优惠券',
        path: 'coupon-list',
      },
      {
        name: '新增优惠券',
        path: 'coupon-add',
        hideInMenu: true,
      },
    ],
  },
  {
    name: '数据管理',
    icon: 'area-chart',
    path: 'data',
    authority: 'admin',
    children: [
      {
        name: '概况',
        path: 'analysis',
      },
    ],
  },
  {
    name: '前端数据',
    icon: 'tablet',
    path: 'index',
    authority: 'admin',
    children: [
      {
        name: 'Banner管理',
        path: 'banner',
      },
      {
        name: '保存Banner',
        path: 'banner-save',
        hideInMenu: true,
      },
      {
        name: '分组管理',
        path: 'group',
      },
      {
        name: '分组保存',
        path: 'group-save',
        hideInMenu: true,
      },
      {
        name: '分组商品',
        path: 'group-goods',
        hideInMenu: true,
      },
      {
        name: '活动管理',
        path: 'activity',
      },
      {
        name: '活动编辑',
        path: 'activity-save',
        hideInMenu: true,
      },
    ],
  },
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let {path} = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
